import request from '@/utils/request'
import { da } from 'element-plus/es/locale'

export const getBooks = <T>() => {
	return request<T>('/books', 'GET')
}

export const addBooks = <T>(data: object) => {
	return request<T>('/books', 'POST', data)
}

export const editBooks = <T>(data: object) => {
	return request<T>('/books', 'PUT', data)
}

export const delBooks = <T>(id: number) => {
	return request<T>(`/books/${id}`, 'DELETE')
}

// 瑞吉点餐登录
export const login = <T>(data: object) => {
	return request<T>('/employee/login', 'POST', data)
}

// 瑞吉点餐退出登录
export const logout = <T>() => {
	return request<T>('/employee/logout', 'POST')
}

// 新增员工
export const save = <T>(data: object) => {
	return request<T>('/employee', 'POST', data)
}

// 员工管理分页查询
export const page = <T>(data: object) => {
	return request<T>('/employee/page', 'POST', data)
}

/**
 * 修改员工信息
 * @param data 员工信息JSON数据
 */
export const updateEmployee = <T>(data: object) => {
	return request<T>('/employee', 'PUT', data)
}

/**
 * 根据员工id获取员工信息
 * @param id 员工id
 * @returns promise
 */
export const getByIdUserInfo = <T>(id: string) => {
	return request<T>(`/employee/${id}`, 'GET')
}

/**
 * 新增分类接口
 * @param data 新增分类数据
 * @returns promise
 */
export const saveClassify = <T>(data: object) => {
	return request<T>('/category', 'POST', data)
}

/**
 * 分类管理分页查询
 * @param data 分页参数
 * @returns promise
 */
export const classifyPage = <T>(data: object) => {
	return request<T>('/category/page', 'POST', data)
}

/**
 * 删除分类
 * @param id 分类id
 * @returns promise
 */
export const deleteClassify = <T>(id: T) => {
	return request<T>(`/category?id=${id}`, 'DELETE')
}

/**
 * 修改分类
 * @param data 分类数据
 * @returns promise
 */
export const updateClassify = <T>(data: object) => {
	return request<T>('/category', 'PUT', data)
}

/**
 * 获取所有分类数据
 * @returns promise
 */
export const getAllCategory = <T>() => {
	return request<T>('/category/getAll', 'GET')
}

/**
 * 图片下载
 * @param data.name 图片名称
 * @returns
 */
export const downloadImg = <T>(data: object) => {
	return request<T>('/common/download', 'GET', data, { responseType: 'blob' })
}

/**
 * 根据类型获取分类
 * @param data
 * @returns
 */
export const getCategoryList = <T>(data: object) => {
	return request<T>('/category/list', 'GET', data)
}

/**
 * 新增菜品
 * @param data 菜品信息
 * @returns
 */
export const saveDish = <T>(data: object) => {
	return request<T>('/dish', 'POST', data)
}

/**
 * 获取菜品分页
 * @param data
 * @returns
 */
export const dishPage = <T>(data: object) => {
	return request<T>('/dish/page', 'GET', data)
}

/**
 * 根据菜品id获取详情
 * @param id 菜品id
 * @returns
 */
export const getDishInfo = <T>(id: string) => {
	return request<T>('/dish/' + id, 'GET')
}

/**
 * 修改菜品
 * @param data 菜品数据
 * @returns
 */
export const updateDish = <T>(data: object) => {
	return request<T>('/dish', 'PUT', data)
}

export const batchUpdateStatusApi = <T>(data: object) => {
	return request<T>('/dish/batchUpdateStatus', 'PUT', data)
}

/**
 * 删除菜品
 * @param id 菜品id
 * @returns
 */
export const delDish = <T>(ids: object) => {
	return request<T>(`/dish`, 'DELETE', ids)
}

/**
 * 根据条件查询菜品数据
 * @param data 查询条件
 * @returns
 */
export const getDishList = <T>(data: object) => {
	return request<T>('/dish/list', 'GET', data)
}

/**
 * 根据条件查询菜品及口味数据
 * @param data 查询条件
 * @returns
 */
export const dishFlavorList = <T>(data: object) => {
	return request<T>('/dish/dishFlavorList', 'GET', data)
}

/**
 * 保存套餐和关联的菜品数据
 * @param data 套餐数据
 * @returns
 */
export const saveSetmealWithDish = <T>(data: object) => {
	return request<T>('/setmeal', 'POST', data)
}

/**
 * 分页查询套餐数据
 * @param data 分页条件
 * @returns
 */
export const querySetmealPage = <T>(data: object) => {
	return request<T>('/setmeal/page', 'GET', data)
}

/**
 * 根据条件查询所有套餐分类数据
 * @param data 查询条件
 * @returns
 */
export const getSetmealList = <T>(data: object) => {
	return request<T>('/setmeal/list', 'GET', data)
}

/**
 * 删除套餐
 * @param data id 数组
 * @returns
 */
export const deleteSetmeal = <T>(data: string[]) => {
	return request<T>(`/setmeal`, 'DELETE', data)
}

/**
 * 根据id查询套餐详情
 * @param id 套餐id
 * @returns
 */
export const getSetmealInfo = <T>(id: string) => {
	return request<T>(`/setmeal/${id}`, 'GET')
}

/**
 * 修改套餐
 * @param data 套餐数据
 * @returns
 */
export const updateSetmeal = <T>(data: object) => {
	return request<T>('/setmeal', 'PUT', data)
}

/**
 * 根据id修改套餐售卖状态
 * @param ids id数组
 * @returns
 */
export const updateSetmealStatus = <T>(data: object) => {
	return request<T>('setmeal/updateStatus', 'PUT', data)
}

/**
 * 保存地址
 * @param data 地址信息
 * @returns
 */
export const saveAddress = <T>(data: object) => {
	return request<T>('addressBook', 'POST', data)
}

/**
 * 查询所有地址信息
 * @returns
 */
export const getAddressList = <T>() => {
	return request<T>('addressBook/list', 'GET')
}

/**
 * 设置默认地址
 * @param data 地址信息
 * @returns
 */
export const putIsDefault = <T>(data: object) => {
	return request<T>('addressBook', 'PUT', data)
}

/**
 * 添加购物车
 * @param data 购物车数据
 * @returns
 */
export const addShoppingCart = <T>(data: object) => {
	return request<T>('shoppingCart', 'POST', data)
}

/**
 * 查询购物车数据
 * @param data
 * @returns
 */
export const shoppingCartList = <T>() => {
	return request<T>('shoppingCart/list', 'GET')
}

/**
 * 清空购物车
 * @returns 
 */
export const clearShoppingCart = <T>() => {
	return request<T>('shoppingCart/clear', 'DELETE')
}

/**
 * 提交订单
 * @param data 订单数据
 * @returns 
 */
export const submitOrder = <T>(data:object) => {
	return request<T>('orders/submit','POST',data)
}